
import sys

import numpy as np
from TrainingData import TrainingData
from TestingData import TestingData
from RecurrentNeural import Recurrent
from Network import Network
from ConstantObj import ConstantObj
from ResultAnalysis import ResultAnalysis


print 'agr1 is training file'
print 'agr2 is test file'
print 'agr3 really training sample used amount, when sampleDateAmmount is -1, whole example will be training'
print 'agr4 training repeat times'
print 'agr5 really test used data amount, when sampleDateAmmount is -1, whole data will be test'
print 'agr6 hidden layer node amount'
print 'agr7 learning Rate'

#if (not sys.argv[1].strip()) or (not sys.argv[2].strip()) or (not sys.argv[3].strip()) or (not sys.argv[4].strip()) or (not sys.argv[5].strip()) or (not sys.argv[6].strip()) or (not sys.argv[7].strip()):
if len(sys.argv)!=8:
    sys.exit()


print 'training file is                      :',sys.argv[1]
print 'test file is                          :',sys.argv[2]
print 'really training sample used amount is :',sys.argv[3]
print 'training repeat times is              :',sys.argv[4]
print 'really test used data amount is       :',sys.argv[5]
print 'hidden layer node amount is           :',sys.argv[6]
print 'learning Rate is                      :',sys.argv[7]
 
# network: neural network class
# sampleDateAmmount: really training sample used amount, when sampleDateAmmount is -1, whole example will be training
# repeatTimes: training repeat times
# hiddenNodeAmount: hidden layer node amount
# learning Rate




print "start----------"
'''
Traing data and test data from KDD Cup 1999 Data Set
'''

training = TrainingData(sys.argv[1])


recurrent = Recurrent()
network = Network();
resultAnalysis = ResultAnalysis()

normalData = recurrent.normalize(training.training)

print " input data shape is:", np.array(normalData).shape

#network = recurrent.perceptionLearning(normalData,network)



#
network = recurrent.BackPropLearing(normalData,network,np.int(sys.argv[3]),np.int(sys.argv[4]),np.int(sys.argv[6]),np.float(sys.argv[7]))

inputLayerWeightArr = network.getLastInputLayerWeightArr()
hiddenLayerWeight = network.getLastHiddenWeightArr()


testing = TestingData(sys.argv[2])

print "testing data shape:",testing.testing.shape


testData = recurrent.normalize(testing.testing)

subTestData = testData


#testResult = recurrent.testData(testData,network)
testResult = recurrent.testDataByBackProp(subTestData,network,np.int(sys.argv[5]))


print "test result shape",testResult.shape

errLineNum = resultAnalysis.compareResult(testResult)


#testing.printData()